package com.adolph.netty.nettydemo;

import com.adolph.netty.dto.MessageObj;
import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.CharsetUtil;

import java.util.List;

/**
 * 〈功能概述〉<br>
 *
 * @author: wangxiangjun
 * @date: 2020-10-13 15:59
 */

public class ObjToStringEndecoder extends MessageToByteEncoder<MessageObj> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MessageObj msg, ByteBuf out) throws Exception {
        String tempStr = JSON.toJSONString(msg);
        out.writeBytes(tempStr.getBytes());
    }
}
